package json;

import java.io.File;
import java.io.IOException;
import java.util.List;

import modelo.Cupon;
import modelo.Oferta;
import modelo.Producto;
import modelo.Venta;

import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

public class JacksonReader implements IReader {

	private String productsFile;
	private String offerProductsFile;
	private String offerSellFile;
	private String sellsFile;
	private String cuponsFile;
	
	private ObjectMapper mapper;

	public JacksonReader() {
		this.productsFile = null;
		this.offerProductsFile = null;
		this.offerSellFile = null;
		this.sellsFile = null;
		
		mapper = new ObjectMapper();
		mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker()
                .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
                .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
                .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
                .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
	}

	public List<Producto> readProducts()
			throws IOException {

		List<Producto> jsonRead = mapper.readValue(new File(productsFile),
				new TypeReference<List<Producto>>() {
				});

		return jsonRead;
	}

	public List<Oferta> readOfferProducts()
			throws IOException {

		
		List<Oferta> jsonRead = mapper.readValue(new File(offerProductsFile),
				new TypeReference<List<Oferta>>() {
				});

		return jsonRead;
	}
	
	public List<Oferta> readOfferSell()
			throws IOException {

		List<Oferta> jsonRead = mapper.readValue(new File(offerSellFile),
				new TypeReference<List<Oferta>>() {
				});

		return jsonRead;
	}

	@Override
	public List<Venta> readSells() throws IOException {
		List<Venta> jsonRead = mapper.readValue(new File(sellsFile),
				new TypeReference<List<Venta>>() {
				});

		return jsonRead;
	}

	@Override
	public List<Cupon> readCupons() throws IOException {
		List<Cupon> jsonRead = mapper.readValue(new File(cuponsFile),
				new TypeReference<List<Cupon>>() {
				});

		return jsonRead;
	}

	public void setProductsFile(String productsFile) {
		this.productsFile = productsFile;
	}

	public void setOfferProductsFile(String offerProductsFile) {
		this.offerProductsFile = offerProductsFile;
	}

	public void setOfferSellFile(String offerSellFile) {
		this.offerSellFile = offerSellFile;
	}

	public void setSellsFile(String sellsFile) {
		this.sellsFile = sellsFile;
	}

	public void setCuponsFile(String cuponsFile) {
		this.cuponsFile = cuponsFile;
	}

	

}
